<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">

<!-- 公共头部引入 header.html -->
<head th:replace="common/header"></head>
<body>
<div class="page-loading">
    <div class="ball-loader">
        <span></span><span></span><span></span><span></span>
    </div>
</div>
<div style="overflow: auto">
    <form class="layui-form model-form" action="" id="queryForm"
          shiro:hasPermission="system:joint:addData">
        <div class="layui-form-item">
            <label class="layui-form-label required-label">系统名称<span style="color: red">*</span></label>
            <div class="layui-input-block">
                <input type='text' name="name" id="name" lay-verType="tips"
                       lay-verify="required" placeholder="设备名称" autocomplete="off"
                       class="layui-input">
            </div>

        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required-label">资源编码<span style="color: red">*</span></label>
            <div class="layui-input-block">
                <input type='text' id="code" name="code" lay-verType="tips" lay-verify="required|lenStrTwentyFour"
                       placeholder="平台系统资源编码23位字符串" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required-label">行政区域码<span style="color: red">*</span></label>
            <div class="layui-input-block">
                <input type='text' name="region_code" id="region_code" lay-verify="required|lenStrNum"
                       lay-verType="tips"
                       placeholder="所属行政区域码"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required-label">平台地址<span style="color: red">*</span></label>
            <div class="layui-input-block">
                <input type='text' name="address" id="address" lay-verify="required" lay-verType="tips"
                       placeholder="接入访问地址（如：http://127.0.0.1:80/xx）"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required-label">网络地址<span style="color: red">*</span></label>
            <div class="layui-input-block">
                <input type='text' name="url" id="url" lay-verify="required" lay-verType="tips"
                       placeholder="平台访问地址如：http://127.0.0.1:80"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required-label">心跳地址<span style="color: red"></span></label>
            <div class="layui-input-block">
                <input type='text' name="heart_url" id="heart_url" lay-verify="" lay-verType="tips"
                       placeholder="使用白皮书协议时心跳地址.可为空，为空时取接入网络地址"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">

            <div class="layui-inline">
                <label class="layui-form-label required-label">经度<span style="color: red">*</span></label>
                <div class="layui-input-block">
                    <input type='text' name="longitude" id="longitude" lay-verify="required|zbj" lay-verType="tips"
                           placeholder="经度"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label required-label">纬度<span style="color: red">*</span></label>
                <div class="layui-input-block">
                    <input type='text' name="latitude" id="latitude" lay-verify="required|zbw" lay-verType="tips"
                           placeholder="纬度"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label required-label">证书编号<span style="color: red"></span></label>
                <div class="layui-input-block">
                    <input type='text' name="cert_cn" id="cert_cn" lay-verify="" lay-verType="tips"
                           placeholder="安全证书编号12位字符串"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">状态<span style="color: red">*</span></label>
                <div class="layui-input-block">
                    <select id="status" name="status">
                        <option value="1">---启用---</option>
                        <option value="2">---禁用---</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-form-item">

            <div class="layui-inline">
                <label class="layui-form-label required-label">覆盖面积</label>
                <div class="layui-input-block">
                    <input type='text' name="square" id="square" lay-verify="" lay-verType="tips"
                           placeholder="如:30(平方公里)"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label required-label">覆盖人口</label>
                <div class="layui-input-block">
                    <input type='text' name="population" id="population" lay-verify="" lay-verType="tips"
                           placeholder="如：300(万人)"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label required-label">联系人</label>
                <div class="layui-input-block">
                    <input type='text' name="linkman" id="linkman" lay-verify="" lay-verType="tips"
                           placeholder="联系人"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label required-label">联系电话</label>
                <div class="layui-input-block">
                    <input type='text' name="phone" id="phone" lay-verify="" lay-verType="tips"
                           placeholder="联系电话"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>


        <div style="margin: 0 0 0 50%;">
            <button shiro:hasPermission="system:joint:addData" type="button" class="layui-btn" lay-submit="jointSystemAdd"
                    lay-filter="jointSystemAdd">保存设置
            </button>
        </div>
    </form>
</div>
<!--</div>-->
<!-- js部分 -->

<script type="text/javascript" th:inline="javascript">
    var parentId = $(".butvalue").attr("parentId");
    layui.use(['jquery', 'layer', 'form', 'formSelects', 'admin', 'slider', 'element'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var dtree;
        var admin = layui.admin;
        var slider = layui.slider;
        form.render();
        /* 回显 */
        // var local = [[ ${local}]];
        form.on("submit(jointSystemAdd)", function (data) {
            let name = $('#name').val();
            let code = $('#code').val();
            let region_code = $('#region_code').val();
            let cert_cn = $('#cert_cn').val();
            let address = $('#address').val();
            let url = $('#url').val();
            let longitude = $('#longitude').val();
            let latitude = $('#latitude').val();
            let status = $('#status').val();
            let square = $('#square').val();
            let population = $('#population').val();
            let linkman = $('#linkman').val();
            let phone = $('#phone').val();
            let heart_url = $('#heart_url').val();

            admin.ajax({
                url: '/platform/system/addData',
                type: 'POST',
                data: {
                    name: name,
                    code: code,
                    region_code: region_code,
                    cert_cn: cert_cn,
                    address: address,
                    url: url,
                    longitude: longitude,
                    latitude: latitude,
                    status: status,
                    square: square,
                    population: population,
                    linkman: linkman,
                    phone: phone,
                    heart_url: heart_url,
                },
                //dataType:'json',
                success: function (data) {
                    if (data.success) {
                        layer.msg(data.msg, {icon: 1, shade: 0.4, time: 1500});
                        setTimeout('parent.layer.closeAll()',1500);
                        setTimeout('parent.jointTable()',1500);
                    } else {
                        layer.msg(data.msg, {icon: 2, shade: 0.4, time: 1500});
                    }
                },
                error: function (error) {
                    layer.msg("网络异常，请稍后尝试!", {icon: 2, shade: 0.4, time: 1500});
                }
            });

            return false;
        });


        form.verify({
            ip: function (value, item) { //value：表单的值、item：表单的DOM对象
                if (!new RegExp("^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9]):(\\d{1,5})$").test(value)) {
                    return '请输入正确的IP地址!';
                }
            },
            num: function (value, item) { //value：表单的值、item：表单的DOM对象
                if (!new RegExp("^\\d+$").test(value)) {
                    return '必须是全数字!';
                }
            },
            zbj: function (value, item) { //value：表单的值、item：表单的DOM对象
                var reg = /^[\-\+]?(0(\.\d{1,10})?|([1-9](\d)?)(\.\d{1,10})?|1[0-7]\d{1}(\.\d{1,10})?|180\.0{1,10})$/;
                if (!reg.test(value)) {
                    return '请输入正确经度坐标(支持小数点后6位)!';
                }
            },
            zbw: function (value, item) { //value：表单的值、item：表单的DOM对象
                var reg = /^[\-\+]?((0|([1-8]\d?))(\.\d{1,11})?|90(\.0{1,11})?)$/;
                if (!reg.test(value)) {
                    return '请输入正确经度纬度(支持小数点后6位)!';
                }
            },
            lenStr: function (value, item) {
                if (value.length != 4) {
                    return "型号编号限制4位字符!";
                }
            },
            lenStrNum: function (value, item) {
                if (value.length != 12) {
                    return "限制12位字符!";
                }
            },
            lenStrTwentyFour: function (value, item) {
                if (value.length != 23) {
                    return "设备资源编码限制23位字符!";
                }
            },
        });

    });
</script>
</body>
</html>